/**
 * Reference book:
 * "Operative Systems", A. Silberschatz, P Baer Galvin, G. Gagne.
 */
package threads;

import java.util.Stack;

/**
 * @author michele
 *
 */
public class LauncherThread extends Thread {
	
	private Stack<Integer> mbox = new Stack<Integer>();
	private MyThread prod1, prod2, prod3, cons1;

	/**
	 * 
	 */
	public LauncherThread() {
		prod1 = new Producer("prod1", mbox, 1200);
		prod2 = new Producer("prod2", mbox, 600);
		prod3 = new Producer("prod3", mbox, 300);
		cons1 = new Consumer("cons1", mbox, 0);
	}
	
	public void go(){
		prod1.start();
		cons1.start();
		prod2.start();
		prod3.start();
		
		try {
			sleep(3000);
			prod3.sleepThread();
			sleep(5000);
			prod2.stopMyThread();
			prod3.stopMyThread();
			prod1.stopMyThread();
			cons1.stopMyThread();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		
	}
	
	
	
	public static void main(String[] args){
		LauncherThread launcher = new LauncherThread();
		launcher.go();
	}

}
